import java.sql.*;

import DBside.Tools;

public class SQLTable {
	ResultSetMetaData resultSetMetaData;
	ResultSet resultSet;
	
	
	public SQLTable(ResultSet resultSet){
		this.resultSet = resultSet;
		try {
			this.resultSetMetaData = this.resultSet.getMetaData();
		} catch (SQLException e) {
			Tools.printError("getting Table properties", e);
		}
	}
	
	public String getTableName(){
		try {
			return this.resultSetMetaData.getTableName(0);
		} catch (SQLException e) {
			Tools.printError("Get Table Name", e);
			return null;
		}
	}
	
	public int getNumberOfColumns(){
		try {
			return this.resultSetMetaData.getColumnCount();
		} catch (SQLException e) {
			Tools.printError("get Number Of Columns", e);
			return -1;
		}
	}
	
	public String getColumnName(int columnNumber){
		try {
			return resultSetMetaData.getColumnName(columnNumber);
		} catch (SQLException e) {
			Tools.printError("get Column's Name", e);
			return null;
		}
	}
	
	public String[] getTableAttributes(){
		String[] tableAttributes = null;
		tableAttributes = new String[getNumberOfColumns()];
		
		for (int i = 0; i < tableAttributes.length; i++) {
			tableAttributes[i] = getColumnName(i);
		}
		return tableAttributes;
	}
}
